package com.afei.bottomtabbar;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public abstract class BaseActivity extends FragmentActivity implements View.OnClickListener{
    private ImageView back,rightImg1,rightImg2;
    private TextView titleTv,rightText1,rightText2;
    private LinearLayout llMain;
    private View view;
    public Context context;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_activity_page);
        context = this;
        back = findViewById(R.id.back_img);
        rightImg1 = findViewById(R.id.qr_image);
        rightImg2 = findViewById(R.id.right_img2);
        titleTv = findViewById(R.id.title);
        rightText1 = findViewById(R.id.right_text1);
        rightText2 = findViewById(R.id.right_text2);
        llMain = findViewById(R.id.ll_base);
        back.setOnClickListener(this);
        initView();
    }
   public void setTitle(String title){
        titleTv.setText(title);
   }
   public void  setRightImg1(int imgId, View.OnClickListener onClickListener){
       rightImg1.setVisibility(View.VISIBLE);
       rightImg1.setImageResource(imgId);
       rightImg1.setOnClickListener(onClickListener);
   }
    public void  setRightImg2(int imgId, View.OnClickListener onClickListener){
        rightImg2.setVisibility(View.VISIBLE);
        rightImg2.setImageResource(imgId);
        rightImg2.setOnClickListener(onClickListener);
    }
    public void  setRightText1(String text, View.OnClickListener onClickListener){
        rightText1.setVisibility(View.VISIBLE);
        rightText1.setText(text);
        rightText1.setOnClickListener(onClickListener);
    }
    public void  setRightText2(String text, View.OnClickListener onClickListener){
        rightText2.setVisibility(View.VISIBLE);
        rightText2.setText(text);
        rightText2.setOnClickListener(onClickListener);
    }
    protected void contentView(int layoutId){
        view = getLayoutInflater().inflate(layoutId,null);
        if (llMain.getChildCount() > 0){
           llMain.removeAllViews();
        }
        if (view != null)
            llMain.addView(view);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back_img:
                finish();
                break;
        }
    }
    public abstract void initView();
}
